<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Vue收银系统 - 水果店</title>
</head>

<body>
    <div id="cashier-system">
        <h1>欢迎光临 Vue开发的收银系统 - 水果店</h1>
        <div class="product-info">
            <p>苹果 10￥/斤, 折扣 <span>8折</span></p>
        </div>
        <div class="input-section">
            <input type="text" placeholder="请输入你要购买的斤数" v-model="quantity">
        </div>
        <button @click="checkout">结账买单</button>
        <div class="checkout-info">
            <p>结账单: 总价: {{ total }}￥元 折后价: {{ discountedTotal }}￥元 省了: {{ saved }}￥元</p>
        </div>
    </div>

    <!-- 引入Vue.js -->
    <script src="../vue.js"></script>
    <script>
        new Vue({
            el: '#cashier-system',
            data: {
                quantity: 0,
                pricePerKg: 10,
                discount: 0.8,
                total: 0,//总价
                discountedTotal: 0,//折后价
                saved: 0//省了
            },
            methods: {
                //结果计算
                checkout() {
                    this.total = this.quantity * this.pricePerKg;
                    this.discountedTotal = this.total * this.discount;
                    this.saved = this.total - this.discountedTotal;
                }
            },
            watch: {
                quantity(newValue) {
                    if (newValue < 0) {
                        this.quantity = 0;
                    }
                }
            }
        });
    </script>
</body>

</html>